package com.taiyi.renaissancemall.ui.main.imagegoodlist;

import android.content.Intent;

import com.taiyi.renaissancemall.Utils.Utils;
import com.taiyi.renaissancemall.base.BasePresent;
import com.taiyi.renaissancemall.base.MyApp;
import com.taiyi.renaissancemall.bean.BaseResultBean;
import com.taiyi.renaissancemall.bean.EmptyBean;
import com.taiyi.renaissancemall.bean.FindBrandListBean;
import com.taiyi.renaissancemall.bean.ImageGoodsListBean;
import com.taiyi.renaissancemall.bean.SearchKindBean;
import com.taiyi.renaissancemall.net.BaseUrl;
import com.taiyi.renaissancemall.net.HttpUtils;
import com.taiyi.renaissancemall.net.callbck.JsonCallback;
import com.taiyi.renaissancemall.ui.login.LoginActivity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Response;

public class ImageGoodsListPresent extends BasePresent<ImageGoodsListView> {

    public void getProductList() {
        Map<String, String> map = new HashMap<>();
        map.put("lableid", view.getLabelId());
        map.put("pagenum", view.getPageNum());
        map.put("beginprice", view.getLowPrice());
        map.put("endprice", view.getMaxPrice());
        map.put("content", view.getContent());
        map.put("brandid", view.getBrandIds());
        map.put("bvsort", view.getBvSort());
        map.put("pricesort", view.getPriceSort());
        map.put("salesort", view.getSaleSort());
        map.put("categoryid", view.getCategoryId());
        HttpUtils.postRequest(BaseUrl.FIND_COMMODITY_LIST, this, map, new JsonCallback<BaseResultBean<ImageGoodsListBean>>() {
            @Override
            public BaseResultBean<ImageGoodsListBean> convertResponse(Response response) throws Throwable {
                return super.convertResponse(response);
            }

            @Override
            public void onSuccess(com.lzy.okgo.model.Response<BaseResultBean<ImageGoodsListBean>> response) {
                super.onSuccess(response);
                if (response.body().code == 0) {
                    view.onSuccess(response.body().data);
                } else if (response.body().code == -1) {
                    Utils.getSpUtils().remove("token");
                    Intent intent = new Intent(MyApp.getInstance(), LoginActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    MyApp.getInstance().startActivity(intent);
                } else {
                    view.onFailure(response.body().msg_cn);
                }
            }

            @Override
            public void onError(com.lzy.okgo.model.Response<BaseResultBean<ImageGoodsListBean>> response) {
                super.onError(response);
            }
        });
    }


    public void getKindList() {
        Map<String, String> map = new HashMap<>();
        HttpUtils.postRequest(BaseUrl.FIND_BRAND_LIST, this, map, new JsonCallback<BaseResultBean<FindBrandListBean>>() {
            @Override
            public BaseResultBean<FindBrandListBean> convertResponse(Response response) throws Throwable {
                return super.convertResponse(response);
            }

            @Override
            public void onSuccess(com.lzy.okgo.model.Response<BaseResultBean<FindBrandListBean>> response) {
                super.onSuccess(response);
                if (response.body().code == 0) {
                    view.getKindListSuccess(response.body().data);
                } else if (response.body().code == -1) {
                    Utils.getSpUtils().remove("token");
                    Intent intent = new Intent(MyApp.getInstance(), LoginActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    MyApp.getInstance().startActivity(intent);
                } else {

                }
            }

            @Override
            public void onError(com.lzy.okgo.model.Response<BaseResultBean<FindBrandListBean>> response) {
                super.onError(response);
            }
        });
    }


}
